package Day35.map.mapTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hyhWTX
 * @version 1.0
 * @ClassName Test03
 * @date 2022年08月07日 19:39
 * @Description: 3.    设计Account 对象如下：
 * private long id;
 * private double balance;
 * private String password;
 * 要求完善设计，使得该Account 对象能够自动分配id。 给定一个List 如下：
 * List list = new ArrayList();
 * list.add(new Account(10.00, “1234”));
 * list.add(new Account(15.00, “5678”));
 * list.add(new Account(0, “1010”));
 * 要求把List 中的内容放到一个Map 中，该Map 的键为id，值为相应的Account 对象。 最后遍历这个Map，打印所有Account 对象的id 和余额。
 * 编码实现以上功能。
 */
public class Test03 {
    public static void main(String[] args) {
        List<Account> list = new ArrayList<Account>();
        list.add(new Account(10.00, "1234"));
        list.add(new Account(15.00, "5678"));
        list.add(new Account(0, "1010"));

        Map<Long, Account> map = new HashMap<Long, Account>();

        for (Account a : list) {
            Long id = (long) (Math.random() * 1000000000);
            map.put(id, a);
        }

        map.forEach((key, value) -> {
            System.out.println("id:" + key + "  余额：" + value.getBalance());
        });
    }
}
    class Account{
        private long id;
        private double balance;
        private String password;
        public Account(double balance, String password) {
            super();
            this.balance = balance;
            this.password = password;
        }
        public Account(long id, double balance, String password) {
            super();
            this.id = id;
            this.balance = balance;
            this.password = password;
        }
        public long getId() {
            return id;
        }
        public void setId(long id) {
            this.id = id;
        }
        public double getBalance() {
            return balance;
        }
        public void setBalance(double balance) {
            this.balance = balance;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
    }


